package com.sz.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sz.mapper.TDealMapper;
import com.sz.model.PageBean;
import com.sz.model.TDeal;
import com.sz.service.ITDealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TDealServiceImpl implements ITDealService {

    @Autowired
    private TDealMapper tDealMapper;

    @Override
    public PageBean<TDeal> getAllDeal(int index, int size, String account) {
        PageHelper.startPage(index, size);
        List<TDeal> list = tDealMapper.getAllDeal(account);
        Page<TDeal> plist = (Page<TDeal>) list;
        PageBean<TDeal> pb = new PageBean<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()

        );
        return pb;
    }

    @Override
    public PageBean<TDeal> getByCondition(int index, int size, String userAccount,String startTime, String endTime, String selectTime, String condition) {
        System.out.println("-----------------------------");
        System.out.println("index = " + index);
        System.out.println("size = " + size);
        System.out.println("startTime = " + startTime);
        System.out.println("endTime = " + endTime);
        System.out.println("selectTime = " + selectTime);
        System.out.println("condition = " + condition);
        System.out.println("userAccount = " + userAccount);
        PageHelper.startPage(index, size);
        List<TDeal> list = tDealMapper.getByCondition(userAccount, startTime, endTime, selectTime, condition);
        Page<TDeal> plist = (Page<TDeal>) list;
        PageBean<TDeal> pb = new PageBean<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()

        );
        return pb;
    }
}
